package com.weijie.relaxed.views;

import com.weijie.relaxed.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TabButton extends LinearLayout {

	ImageView icon;
	TextView text;
	
	public TabButton(Context context, AttributeSet attrs) {
		super(context, attrs);
		TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.relaxed, 0, 0);
		String txt = ta.getString(R.styleable.relaxed_tab_text);
		Drawable ic = ta.getDrawable(R.styleable.relaxed_tab_icon);
		ta.recycle();
		inflate(context, R.layout.view_tabbar, this);
		text = (TextView) findViewById(R.id.tab_text);
		icon = (ImageView) findViewById(R.id.tab_icon);
		if(!txt.equals("")) {
			text.setText(txt);
		}
		if(ic!=null) {
			icon.setImageDrawable(ic);
		}
	}

	
	public void setSelected(boolean b) {
		icon.setSelected(b);
		text.setSelected(b);
		super.setSelected(b);
	}
	
	public boolean isSelected() {
		return icon.isSelected();
	}
}
